<template>
	<view class="container">
		<uni-section title="图" sub-title="" type="line">
			<img :src="'http://localhost:8090'+list.icon" style="width: 100%; height: 200px;">
		</uni-section>
		<uni-section title="名称" sub-title="" type="line">
			{{list.name}}
		</uni-section>
		<uni-section title="类别" sub-title="" type="line">
			{{list.typename}}
		</uni-section>
		<uni-section title="价格" sub-title="" type="line">
			{{list.price}}
		</uni-section>
		<uni-section title="描述" sub-title="" type="line">
			{{list.description}}
		</uni-section>
		<view class="" style="display: flex; justify-content: flex-end;">
			<uni-easyinput v-model="data.comment" placeholder="请输入评论内容" />
			<button type="default" size="mini" @click="comment">发表</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: {},
				list: [],
				data: {
					"foodid": 1,
					"userid": 1,
					"comment": "",
					"postdate": "2022-09-09"
				}
			}
		},
		methods: {
			comment() {
				uni.request({
					url: 'http://localhost:8090/foodapp/comment/addone',
					method: 'POST',
					data: this.data,
					success: res => {
						if (res.data.success) {
							uni.showToast({
								icon: 'none',
								title: '发表成功'
							});
						} else{
							uni.showToast({
								icon: 'none',
								title: '发表失败'
							});
							this.data.comment = ''
						}
					},
					fail: () => {},
					complete: () => {}
				});
			}
		},
		onLoad(e) {
			console.log(e);
			this.id = e.id
			uni.request({
				url: 'http://localhost:8090/foodapp/food/findone',
				method: 'POST',
				data: {
					id: this.id
				},
				success: res => {
					if (res.data.success) {
						this.list = res.data.data
					}
				},
				fail: () => {},
				complete: () => {}
			});
		}
	}
</script>

<style>

</style>
